home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 293_01 / totarga.c < prev   
C/C++ Source or Header  |  1989-08-23  |  2KB  |  68 lines

  1. /* This is a simple module to convert image files from
  2.    the reconstruction package to AT&T Targa board
  3.     format                                       */
  4. #include <stdio.h>
  5. #include <math.h>
  6. #include <fcntl.h>
  7. #include <sys\types.h>
  8. #include <sys\stat.h>
  9. main()
  10. {int fin,fout,i,j,k;
  11.   unsigned char c,outbuf[256][3];
  12.   unsigned char inbuf[256],fnamein[20],fnameout[20];
  13.   printf(" Enter fin: ");  /* The file to be converted */
  14.   scanf("%s",fnamein);
  15.   printf("Enter fout: ");  /* Name of destination file */
  16.   scanf("%s",fnameout);
  17.   printf("Enter number of lines: "); /* of image */
  18.   scanf("%d",&k); 
  19.   fin=open(fnamein,O_RDONLY|O_BINARY,0);
  20.   fout=open(fnameout,O_CREAT|O_WRONLY|O_BINARY);
  21.  
  22.               /* Write Header */
  23.   c=0;
  24.   write(fout,&c,1);
  25.   write(fout,&c,1);
  26.   c=2;
  27.   write(fout,&c,1);
  28.   c=0;
  29.   for(i=0;i<6;i++)write(fout,&c,1);
  30.   c=1;
  31.   write(fout,&c,1);
  32.   c=0;
  33.   for(i=0;i<3;i++)write(fout,&c,1);
  34.   c=1;
  35.   write(fout,&c,1);
  36.   c=0;
  37.   write(fout,&c,1);
  38.   c=1;
  39.   write(fout,&c,1);
  40.   c=24;
  41.   write(fout,&c,1);
  42.   c=0;
  43.   write(fout,&c,1);
  44.  
  45.    /* Convert raw data to RGB */
  46.  
  47.   for(i=0;i<k;i++){
  48.       read(fin,inbuf,256);
  49.       for(j=0;j<256;j++)if(inbuf[j]!=0)
  50.            outbuf[j][0]=outbuf[j][1]=outbuf[j][2]=inbuf[j];
  51.       else{
  52.            outbuf[j][1]=outbuf[j][2]=0;
  53.            outbuf[j][0]=255;
  54.       }
  55.       write(fout,outbuf,768);
  56.   }
  57.   close(fin);
  58.  
  59.   /* add blank blue lines to image with less than 256 lines */
  60.  
  61.   for(i=0;i<256;i++){ 
  62.        outbuf[i][0]=255;
  63.        outbuf[i][1]=outbuf[i][2]=0;
  64.   }
  65.   for(i=0;i<(256-k);i++) write(fout,outbuf,768);
  66.   close(fout);
  67.  }
  68.